package com.daoyin.ssph.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.daoyin.ssph.bean.Administrator;
import com.daoyin.ssph.service.AdminService;

public class AdminAction {
	
	@Resource
	private AdminService as;
	private String username;
	public void setUsername(String username) {
		this.username = username;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	private String password;

	public void setAs(AdminService as) {
		this.as = as;
	}

	public String execute() throws IOException{

		Administrator admin = new Administrator();
		
		admin.setName(username);
		admin.setPassword(password);
		String str = as.query(admin);
		if(("success").equals(str)){
			ServletActionContext.getRequest().getSession(true).setAttribute("user", username);

			return "success";

		}else if(("padfail").equals(str)){
			System.out.println("padfail");
	
		}else if(("notexist").equals(str)){
			System.out.println("notexist");

		}

		return "fail";
		
	}

}
